package com.woniuxy.carlife.carlifenewcomplaintsweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.carlife.carlifecommonsweb.util.CopyUtil;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.dto.StoreMessageDto;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.param.StoreMessageParam;
import com.woniuxy.carlife.carlifenewcomplaintsweb.domain.StoreMessage;
import com.woniuxy.carlife.carlifenewcomplaintsweb.mapper.StoreMessageMapper;
import com.woniuxy.carlife.carlifenewcomplaintsweb.service.StoreMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yp
 * @ClassName:StoreMessageServiceImpl
 * @Description:门店消息服务
 * @date 2021/4/7 2:32
 **/
@Service
public class StoreMessageServiceImpl extends ServiceImpl<StoreMessageMapper, StoreMessage> implements StoreMessageService {


    @Resource
    private  StoreMessageMapper storeMessageMapper;


    /*
     * 功能描述〈新增门店消息〉
     * @author:yp
     * @param:StoreMessageParam
     * @return:
     * @Date 2021/4/12 14:00
     * @throws
     */
    @Override
    public int addStoreMessage(StoreMessageParam storeMessageParam) {
        StoreMessage storeMessage= CopyUtil.getOne(storeMessageParam,StoreMessage.class);
        int num = storeMessageMapper.insert(storeMessage);
        return num;
    }


    /*
     * 功能描述〈查询门店消息〉
     * @author:yp
     * @param:StoreMessageParam
     * @return:List<StoreMessageDto>
     * @Date 2021/4/12 14:05
     * @throws
     */
    @Override
    public List<StoreMessageDto> findStoreMessage(Integer storeId) {
        QueryWrapper<StoreMessage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("store_id", storeId);
        queryWrapper.eq("store_message_state",1);
        queryWrapper.or();
        queryWrapper.eq("store_message_state",2);
        List<StoreMessage> list = storeMessageMapper.selectList(queryWrapper);
        List<StoreMessageDto> list1 = CopyUtil.getList(list,StoreMessageDto.class);
        return list1;
    }

    /*
     * 功能描述〈修改门店消息状态〉
     * @author:yp
     * @param: StoreMessageParam
     * @return:
     * @Date 2021/4/12 14:08
     * @throws
     */
    @Override
    public int updateStoreMessage(Integer storeMessageId) {
        QueryWrapper<StoreMessage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("store_message_id", storeMessageId);
       StoreMessage storeMessage = new StoreMessage();
       storeMessage.setStoreMessageState(2);
        int num = storeMessageMapper.update(storeMessage,queryWrapper);
        return num;
    }

    /*
     * 功能描述〈删除门店消息〉
     * @author:yp
     * @param:
     * @return:
     * @Date 2021/4/12 14:10
     * @throws
     */
    @Override
    public int deleteStoreMessageParam(Integer storeMessageId) {
        QueryWrapper<StoreMessage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("store_message_id",storeMessageId);
        StoreMessage storeMessage = new StoreMessage();
        storeMessage.setStoreMessageState(3);
        int num = storeMessageMapper.update(storeMessage,queryWrapper);
        return num;
    }
}
